package com.anolesoft.qxgl.controller.giveRole;

import com.anolesoft.common.core.constant.HttpStatus;
import com.anolesoft.common.core.web.domain.AjaxResult;
import com.anolesoft.qxgl.dto.giveRole.GiveRoleDto;
import com.anolesoft.qxgl.service.giveRole.inf.GiveRoleServiceInf;
import com.anolesoft.yr.util.Constants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/qjwl/giveRole")
public class GiveRoleController {
    @Autowired
    private GiveRoleServiceInf giveRoleServiceInf;

    /**
     * 查询当前人员拥有角色
     *
     * @param giveRoleDto
     * @return
     */
    @PostMapping(value = "/select", produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public AjaxResult selectOneGiveRole(@RequestBody GiveRoleDto giveRoleDto) {
        String userUid = giveRoleDto.getUserUid();
        List<String> allList = giveRoleServiceInf.selectOneGiveRole(userUid);
        return new AjaxResult(HttpStatus.SUCCESS, Constants.QUERY_SUCCESS_MESSAGE, allList);
    }

    /**
     * 修改人员角色授权
     *
     * @param giveRoleDto
     * @return
     */
    @PostMapping(value = "/update", produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public AjaxResult updateAuthorization(@RequestBody GiveRoleDto giveRoleDto) {
        int allList = giveRoleServiceInf.updateAuthorization(giveRoleDto);
        return new AjaxResult(HttpStatus.SUCCESS, Constants.QUERY_SUCCESS_MESSAGE);
    }
}
